<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title >小强博客</title>
    <link  rel="stylesheet" type="text/css" href="/Public/css/bootstrap.min.css" />
    <script type="text/javascript" src="/Public/js/jquery-3.1.1.js"></script>
    <script type="text/javascript" src="/Public/js/bootstrap.js"></script>
    <script type="text/javascript" src="/Public/js/layer.js"></script>
</head>
<style>
    .navbar-inverse{
   border-radius: inherit;
    }
    .navbar nav li:hover{
        background-color: white;
    }
</style>
<body>
<nav class="navbar navbar-inverse">
    <div class="container">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header ">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">Blog v1.0</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li class="<?php if( CONTROLLER_NAME == 'Index' ): ?>active<?php endif; ?>"><a href="<?php echo U('Index/index');?>">
                <i class="glyphicon glyphicon-home">&nbsp;</i>首页  <span class="sr-only">(current)</span></a></li>
                <li  class="<?php if( CONTROLLER_NAME == 'Content' ): ?>active<?php endif; ?>"><a href="<?php echo U('Content/index');?>">内容</a></li>
                <li class="<?php if( CONTROLLER_NAME == 'Tools' ): ?>active<?php endif; ?>"><a href="<?php echo U('Tools/index');?>">功能</a></li>
                <li class="<?php if( CONTROLLER_NAME == '' ): ?>active<?php endif; ?>"><a href="#">用户</a></li>

            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="/index.php"> 前台首页</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false"><span>您好 </span>&nbsp;<?php echo ($_SESSION['blog_admin']['name']); ?></a>
                    <ul class="dropdown-menu">
                        <li><a href="<?php echo U('Index/profile');?>">管理档案 </a></li>
                        <li><a href="<?php echo U('Index/quite');?>">注销 </a></li>
                    </ul>
                </li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>
<div class="container">
    <div class="row">

            <div class="btn-group-vertical col-md-2">
    <a  class="btn btn-default  <?php if( CONTROLLER_NAME == 'Links' ): ?>active<?php endif; ?>" href="<?php echo U('Links/index');?>">
    <i class="glyphicon glyphicon-link">&nbsp;</i>链接管理</a>
    <a  class="btn btn-default  <?php if( CONTROLLER_NAME == 'Navs' ): ?>active<?php endif; ?>" href="<?php echo U('Navs/index');?>" >
    <i class="glyphicon glyphicon-th-list">&nbsp;</i>菜单管理</a>
    <a  class="btn btn-default  <?php if( CONTROLLER_NAME == 'Configs' ): ?>active<?php endif; ?>" href="#" >
    <i class="glyphicon glyphicon-cog">&nbsp;</i>配置管理</a>
</div>

        <div class="col-md-10">
            <div class="page-header"><h3><?php echo ($page_title); ?></h3></div>
            <a  class="btn btn-default" href="<?php echo U('Navs/index');?>">菜单</a>
            <a  class="btn btn-default" href="<?php echo U('Navs/add');?>">菜单添加 </a>
            <br><br>
            <div>
                <table class="table table-bordered ">
                    <thead>
                    <tr class="active">
                        <td>id</td>
                        <td>排序</td>
                        <td> 菜单名称</td>
                        <td>状态</td>
                        <td>操作</td>
                    </tr>
                    </thead>
                    <tbody>
                    <?php if(is_array($navs)): foreach($navs as $key=>$n): ?><tr>
                            <td><?php echo ($n['id']); ?></td>
                            <td><input type="text" value="<?php echo ($n['sort']); ?>" onchange="changeSort(this,<?php echo ($n['id']); ?>)"></td>
                            <td><?php echo ($n['name']); ?></td>
                            <td>
                                <?php if($n['status']): ?><span class="label label-success">开启</span>
                                    <?php else: ?>
                                    <span class="label label-danger">关闭</span><?php endif; ?>
                            </td>
                            <td>
                                <a class="btn btn-primary" href="<?php echo U('Navs/edit',array('id'=>$n['id']));?>" >编辑</a>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:delNavs(<?php echo ($n['id']); ?>)">删除</a>
                            </td>
                        </tr><?php endforeach; endif; ?>
                    </tbody>
                </table>
            </div>
        </div>

</div>
    <script>
        function delNavs(id)
        {
            layer.confirm(' 确认删除',{
             btn:['是','不']
        } ,function () {
                $.ajax({
                  'url':"<?php echo U('Navs/delete');?>",
                    'type':'POST',
                    'dataType':'json',
                    'data':{'id':id},
                    success:function(phpReturnData){
                      if(phpReturnData.status==1){
                          layer.msg(phpReturnData.message,{'icon':6},function () {
                              window.location=location;
                          } )
                      }else{
                          layer.msg(phpReturnData.message,{'icon':5});
                      }
                }
                })
            })
        }
        function changeSort(obj,id) {
            //alert(id);
            var csort = $(obj).val();
            $.ajax({
                'url': "<?php echo U('navs/changeSort');?>",
                'type': 'post',
                'dataType': 'json',
                'data': {'id':id, 'sort': csort},
                success:function(phpReturnData)
                {
                    if (phpReturnData.status)
                    {
                        layer.msg(phpReturnData.message, {'icon': 6}, function () {
                            window.location = location;
                        })
                    }
                }
            })
        }
    </script>
</body>
</html>